package com.example.myworkc;

import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.text.InputType;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivityLog extends AppCompatActivity {
    private EditText editText1,editText2;

    private Button buttonLog;
    private CheckBox checkBox_log;
    private SharedPreferences sp;
    private SharedPreferences.Editor editor;
    private Intent intent1,intent2;

    @RequiresApi(api = Build.VERSION_CODES.CUPCAKE)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_log);
        buttonLog=findViewById(R.id.buttonLog);
        checkBox_log=findViewById(R.id.CheckBoxSig_log);
        editText1=findViewById(R.id.editTextLog1);
        editText2=findViewById(R.id.editTextLog2);
        sp=getSharedPreferences("lock", Context.MODE_PRIVATE);//Context.MODE_PRIVATE表示其他文件无法访问这个sp文件
//        editor=sp.edit();
        String id_get=sp.getString("id","");
        editText2.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        String password_get=sp.getString("password","");
        buttonLog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(id_get.equals(editText1.getText().toString().trim()) &&
                        password_get.equals(editText2.getText().toString().trim()))
                {
                intent1 = new Intent(MainActivityLog.this,MainActivity.class);
                startActivity(intent1);
                }
                else
                    Toast.makeText(getApplicationContext(),"账号或密码错误",Toast.LENGTH_LONG).show();
                editText1.setText("");
                editText2.setText("");
            }

        });
        checkBox_log.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                intent2 = new Intent(MainActivityLog.this,MainActivitySig.class);
                startActivity(intent2);
            }
        });
        editText2.setTransformationMethod(new AsteriskPasswordTransformationMethod());
    }
}